import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layouts/default'
import Dialog from '@/views/dialog/dialog'
const _import = require('./_import_' + process.env.NODE_ENV)

import GetUserInfo from '@/views/getUserInfo'
import ChatRoom from '@/views/dialog/chatRoom/index'
import DoctorSession from '@/views/dialog/doctorSession'
import DoctorAidSession from '@/views/dialog/doctorAidSession'
import PataintSession from '@/views/dialog/PataintSession'
import ParientmsgSource from '@/views/dialog/parientMessage/parientmsgSource'
import ParientInfo from '@/views/dialog/parientMessage/parientInfo'
import DrugAdvance from '@/views/components/advance/drugAdvance'
import Phrase from '@/views/dialog/phrase/index'
import PhraseList from '@/views/dialog/phrase/list'
import PhraseEdit from '@/views/dialog/phrase/edit'
import PhraseAdd from '@/views/dialog/phrase/add'
import Group from '@/views/dialog/group/index'
import GroupList from '@/views/dialog/group/list'
import GroupEdit from '@/views/dialog/group/edit'
import GroupAdd from '@/views/dialog/group/add'

Vue.use(Router)

const modules = [
  {
    path: '/',
    name: 'home',
    component: Layout,
    redirect: {
      name: 'getUserInfo'
    },
    meta: {
      title: '铭医在线'
    },
    children: [
      {
        path: 'getUserInfo',
        name: 'getUserInfo',
        component: GetUserInfo
      },
      {
        path: 'dialog',
        name: 'dialog',
        component: Dialog,
        children: [
          {
            path: 'doctorSession',
            name: 'doctorSession',
            meta: {
              title: '患者对话'
            },
            component: DoctorSession
          },
          {
            path: 'doctorAidSession',
            name: 'doctorAidSession',
            meta: {
              title: '患者对话'
            },
            component: DoctorAidSession
          },
          {
            path: 'pataintSession',
            name: 'pataintSession',
            meta: {
              title: '医生对话'
            },
            component: PataintSession
          },
          {
            path: 'parientmsgSource',
            name: 'parientmsgSource',
            meta: { title: '登记信息' },
            component: ParientmsgSource
          },
          {
            path: 'parientInfo',
            name: 'parientInfo',
            component: ParientInfo
          },
          {
            path: 'drugAdvance',
            name: 'drugAdvance',
            meta: {
              title: '药品选择'
            },
            component: DrugAdvance
          },
          {
            path: 'phrase',
            name: 'phrase',
            component: Phrase,
            children: [
              {
                path: 'list',
                name: 'phraseList',
                meta: {
                  title: '选择常用语'
                },
                component: PhraseList
              },
              {
                path: 'edit',
                name: 'phraseEdit',
                meta: {
                  title: '管理常用语'
                },
                component: PhraseEdit
              },
              {
                path: 'add',
                name: 'phraseAdd',
                meta: {
                  title: '添加常用语'
                },
                component: PhraseAdd
              }
            ]
          },
          {
            path: 'group',
            name: 'group',
            component: Group,
            children: [
              {
                path: 'list',
                name: 'groupList',
                meta: {
                  title: '选择分组'
                },
                component: GroupList
              },
              {
                path: 'edit',
                name: 'groupEdit',
                meta: {
                  title: '管理分组'
                },
                component: GroupEdit
              },
              {
                path: 'add',
                name: 'groupAdd',
                meta: {
                  title: '添加分组'
                },
                component: GroupAdd
              }
            ]
          }
        ]
      },
      {
        path: 'chatroom',
        name: 'chatroom',
        component: ChatRoom
      }
    ]
  }
]

const routes = [
  ...modules,
  {
    path: '/500',
    name: 'error500',
    meta: { title: '服务器错误' },
    component: _import('error-pages/500')
  },
  {
    path: '/*',
    name: 'error404',
    meta: { title: '页面不存在' },
    component: _import('error-pages/404')
  }
]

const route = new Router({
  routes
})

route.afterEach(() => {
  window.scrollTo(0, 0)
})

export default route
